"""
@author: 江同学呀
@file: base_numeric_field.py
@date: 2023/8/22 19:45
@desc:
"""


from abc import ABC
from typing import Type, Union, Dict

from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField


class _BaseNumericField(_BaseField, ABC):
    """
    数值类型字段基类
    """
    _type: Type = Union[int, float]

    def __init__(
            self, field_name: str = None, value: Union[int, float] = None, default: Union[int, float] = None, *args,
            **kwargs
    ):
        super(_BaseNumericField, self).__init__(field_name=field_name, value=value, default=default, *args, **kwargs)
        return

    def __get__(self, instance: _Base, owner: Type["_BaseNumericField"]
                ) -> Union["_BaseNumericField", Union[int, float]]:
        return super(_BaseNumericField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: Union[int, float]):
        super(_BaseNumericField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> Union[int, float]:
        return self._value

    @value.setter
    def value(self, value: Union[int, float]):
        self._value: Union[int, float] = value
        return

    def _build(self) -> Dict:
        raise NotImplementedError


